﻿@using System.IO;
@using MudBlazor.Utilities;

<div style="overflow: auto;">
    @CodeComponent(CodeFileName)
</div>

@code {

    [Parameter] public string CodeFileName { get; set; }

    RenderFragment CodeComponent(string code) => builder =>
    {
        try
        {
            var key = typeof(DashboardPageSection).Assembly.GetManifestResourceNames().FirstOrDefault(x => x.Contains($".{code}Code.html"));
            var stream = typeof(DashboardPageSection).Assembly.GetManifestResourceStream(key);
            var reader = new StreamReader(stream);
            {
                var read = reader.ReadToEnd();

                //builder.AddMarkupContent(0, read);
                //builder.AddContent(0, read);

                builder.OpenElement(0, "div");
                builder.AddAttribute(1, "class", "html");

                builder.OpenElement(2, "pre");
                builder.AddContent(3, read);
                builder.CloseElement();

                //builder.OpenElement(3, "li");
                //builder.OpenComponent<NavLink>(4);
                //builder.AddAttribute(5, "href", "/");
                //builder.AddAttribute(6, "Match", NavLinkMatch.All);
                //builder.AddAttribute(7, "ChildContent", (RenderFragment)((builder2) =>
                //{
                //    builder2.AddContent(8, "Home");
                //}));
                //builder.CloseComponent();
                builder.CloseElement();
            }
        }
        catch (Exception)
        {
            // todo: log this
        }
    };
}
